< previous page page_384 next page >

Page 384
Using the Rich Text Box Versus Older File Access Methods
Although opening files for random, sequential, or binary access is fairly simple, at times it can be tedious. Not only do you need to know the filename, but you also need to map an opened file with a particular file number. You also have to explicitly close the file when you're finished working with it. Although it's no binary access file mechanism, the Rich Text Box control makes managing files much simpler.
In short, the Rich Text Box control combines the text box, file operations, simple word-processing, and printing and reporting capabilities in one object. As mentioned earlier, the Rich Text Box can hold huge amounts of information, more so than the conventional text box. Plus, it gives you the flexibility to manage .RTF (rich text) and ASCII files (of any extension, but typically .TXT). If you want to store information in row and column format, simply insert commas and the vbNewLine value where you need it. And when you persist information in the comma-separated value (CSV) format, you can open it and read the information in it using the Random Access or Binary Access methods. In fact, as mentioned earlier, in CSV format, you can export the file to Access, Excel, SQL Server, and other databases that accept CSV files.
Moreover, there are no file numbers to remember. Simply invoke the LoadFile and SaveFile methods of the Rich Text Box, specifying the name of the file and the type of file (defaults to .RTF). If you need more than one file open at a time, create one form with a Rich Text Box control, and create a collection of controller class objects (where each object has its own reference to the form). Want to print the contents of the Rich Text Box? Use the SelPrint method. You can even bind the Rich Text Box to any ODBC-compliant data source to accept huge amounts of information, such as what you get with the Text data type field in SQL Server. Changing fonts and text colors, as well as doing searches for specific words, can all be done in Rich Text Boxes without much tedious effort.
The File Operations Subsystem Object Model
Figure 17.2 shows the interaction of classes needed to open a file of any type, be it binary, random, sequential, or rich text. Figure 17.3 shows the interaction of classes needed to close a file of any type. Although at first glance, there seems to be repetition, in fact, the success open and close file events are really delegations to the next class down in the hierarchy. The IPersistence class instance (or object) owns a reference to the IFileSubsystem class instance. This object, in turn, owns a reference to an instance of a GeneralFile interface implementation class such as RandomFile, SequentialFile, BinaryFile, or RichTextFile. One of these classes does the actual grunt work.

 
< previous page page_384 next page >

If you like this book, buy it!